Repository navigation
Conversation
Since 92fe7c7 (run-command(win32): resolve the path to the Unix shell early, 2024-07-13), `prepare_shell_cmd()` puts the full path that `git_shell_path()` finds for `sh` into `argv[0]`, where it used to put plain "sh" and leave the lookup to `mingw_spawnvpe()`. The two lookups find the same program, but in the BusyBox flavor of MinGit that program is `busybox.exe`, found by the applet fallback in `path_lookup()`. BusyBox picks the applet to run from `argv[0]`, and `busybox.exe` isn't one, so it takes the next argument as the applet's name, and every command that goes through the shell fails: $ git -c alias.t='!echo one; echo two' t -c: applet not found That covers `!` aliases with more than a plain command, and editors, pagers and other configured commands given with arguments (`core.editor="sed -i s/^/x/"` fails the same way). Hooks aren't affected. Put "sh" in `argv[0]` again on Windows. `mingw_spawnvpe()` finds the same `sh` as before, `is_msys2_sh()` already recognizes "sh" and quotes the arguments the same way, and BusyBox now runs its `sh` applet. `git var GIT_SHELL_PATH` still shows the full path. This fixes git-for-windows#5184. Signed-off-by: Sanford Lincoln <12786+sanford@users.noreply.github.com>
It indeed is, and I fear that this PR would make that long-term knob harder. For example, this PR distracts me during the already limited time I have to look into the BusyBox stuff, and #3301 gets less and less attention as a consequence.
Okay, that's good to know. I will match that by stopping my review here ;-) |
|
@sanford thank you for understanding, and for taking my unfortunately quite harsh feedback with good grace! I apologize for my tone. To be quite honest, I really don't like that I fail to find the time to get this MinGit stuff done. Maybe this can serve as an explanation (but not an excuse!) for my inconsiderate reply to you. For years, I am dreaming of having a special opt-in mode in Git for Windows to replace the Git Bash with a |
|
No need to apologise, it was a fair call, and I appreciate the explanation. For what it's worth, we're in the same boat: we run Git inside AppContainer sandboxes, where MSYS2's runtime can't start yet and MinGit-busybox is the only Git that can run hooks and aliases. So a "Git Ash" mode would be very welcome here. I'll put the #3301 testing I offered on the PR itself. |
Fixes #5184.
In the BusyBox flavor of MinGit, every command git runs through the shell fails with
-c: applet not found. That covers!aliases with anything more than a plain command, and editors, pagers and other configured commands that have arguments, likecore.editor="sed -i s/^/x/". Hooks aren't affected: they're started through their#!line, which already works.The cause is 92fe7c7 (run-command(win32): resolve the path to the Unix shell early), which went into 2.46. Since then
prepare_shell_cmd()puts the full path thatgit_shell_path()finds intoargv[0], where it used to put plainsh. In MinGit-busybox that path isbusybox.exe, whichpath_lookup()finds through its applet fallback. BusyBox picks its applet fromargv[0], andbusyboxisn't an applet, so it reads-cas the applet's name.This patch puts
shinargv[0]again, on Windows only.mingw_spawnvpe()still looks up the sameshthatgit_shell_path()reports, andis_msys2_sh()already handles a plainsh, so the arguments are quoted as before.git var GIT_SHELL_PATHstill shows the full path.About the alternatives:
busybox.exeassh.exe(build-extra#746) was declined because of its size.core.shell(Allow specifying at runtime which POSIX shell to use #3301) is still the better long-term knob, and this patch doesn't get in its way. On its own, though, it doesn't fix this bug. Withcore.shellset to the path ofbusybox.exe,argv[0]is stillbusybox.exe. Withcore.shellset to the full path of MinGit's ownash.exe(a 42 kB launcher), it should work, but only once MinGit ships that config. I checked thatash.exe -c '…'works, and that a copy ofash.exenamedsh.exefixes this bug too. That copy would be a packaging-only fix at 42 kB, not the 844 kB of build-extra#746. As far as I can read the code, a bare name likeashwould break hooks: theshspecial case inpath_lookup()returns the name without resolving it, and the#!/bin/shline is then started as the programash.How I tested it: I used MinGit-2.56.1-busybox-mingw64, with
git.exereplaced by builds of v2.56.1.windows.1 with and without this patch. The PATH held only MinGit'smingw64\binand Windows' own folders, and everything ran inside an AppContainer.git.exegit -c "alias.t=!echo one; echo two" t-c: applet not found, exit 127one,two, exit 0git -c "core.editor=sed -i s/^/edited/" commit --allow-empty-c: applet not found, "there was a problem with the editor"post-commithook (#!/bin/sh), also from acore.hooksPathwith a space in itI didn't run Git's test suite on Windows.
This matters most inside Windows' AppContainer sandbox. MSYS2's
sh.execan't start there (microsoft/mxc#1061), and BusyBox-w32 runs fine, so MinGit-busybox is the only Git that can run hooks and aliases in such a sandbox.